package com.study.demo.aop.demo1_2.config;

import com.study.demo.aop.demo1_2.annotation.EnableLogging;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportAware;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;

/**
 * @author: elvin
 * @time: 2019-10-16 13:20
 * @desc:
 **/
@Configuration
public abstract class AbstractLogConfiguration implements ImportAware {
    @Nullable
    protected AnnotationAttributes enableLogging;

    @Override
    public void setImportMetadata(AnnotationMetadata importMetadata) {
        this.enableLogging = AnnotationAttributes.fromMap(
                importMetadata.getAnnotationAttributes(EnableLogging.class.getName(), false));
        if (this.enableLogging == null) {
            throw new IllegalArgumentException(
                    "@EnableLogging is not present on importing class " + importMetadata.getClassName());
        }
    }
}
